<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

require_once(dirname(__FILE__) . '/MY_Model.php');

Class Products_m extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->_table = 'products';
    }

    public function getAllProduct() {
        $this->db->select('prd.*, mnf.manufacturer_name, mnf.billing_address, mnf.shipping_address, mnf.industry, mnf.website, mnf.email, mnf.phone1, mnf.phone2, mnf.fax, cate.name');
        $this->db->from('products as prd');
        $this->db->join('manufacturers as mnf', 'prd.manufacturer = mnf.id', 'left');
        $this->db->join('product_category as cate', 'prd.category = cate.id', 'left');
        $result = $this->db->get()->result();
        return $result;
    }

    public function getAllProductAutoComplete() {
        $this->db->select('prd.id,prd.product_name as label,prd.sale_price');
        $this->db->from('products as prd');
        $result = $this->db->get()->result();
        return $result;
    }

    public function delete_image($product_id, $image_id) {
        $val = $this->db->delete('product_image', array('product_id' => $product_id, 'image_id' => $image_id));
        $str = $this->db->last_query();
        return $val;
    }

    public function getImagesProduct($product_id) {
        $sql = 'SELECT * FROM images WHERE id IN(SELECT image_id FROM product_image WHERE product_id="' . $product_id . '")';
        $result = $this->db->query($sql);
        return $result->result();
    }

}

?>